//  Copyright (c) 2010 Mahesh Sharma,Matt MacDonald
//
//  Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
//
//  The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
//
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  THE SOFTWARE.

package org.prx.prp.model;

import org.prx.prp.utility.DatabaseAdapter;

import android.database.Cursor;

public class Program {
	private Integer programId;
	private String title;
	@SuppressWarnings("unused")
	private String category;
	private String description;
	private String imageUrl;
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getImageUrl() {
		return imageUrl;
	}

	public void setImageUrl(String imageUrl) {
		this.imageUrl = imageUrl;
	}

	@SuppressWarnings("unused")
	private String website;
	private String podcast;
	public Program(int programId, String title, String category,
			String description, String imageUrl, String website, String podcast) {
		super();
		this.programId = programId;
		this.title = title;
		this.category = category;
		this.description = description;
		this.imageUrl = imageUrl;
		this.website = website;
		this.podcast = podcast;
	}

	public Integer getProgramId() {
		return programId;
	}
	public void moveFavorite(Integer fromPosition,Integer toPosition)
	{
		if (fromPosition > toPosition) {
			Cursor c=DatabaseAdapter.executeQuery("update favorite_programs set position = (position + 1) where position < ? and position >= ?",new String[]{fromPosition.toString(),toPosition.toString()});
			c.close();
			
		} else if (fromPosition < toPosition) {
			Cursor c=DatabaseAdapter.executeQuery("update favorite_programs set position = (position - 1) where position > ? and position <= ?",new String[]{fromPosition.toString(),toPosition.toString()});
			c.close();			
		}
		Cursor c=DatabaseAdapter.executeQuery("update favorite_programs set position = ? where id = ?",new String[]{toPosition.toString(),programId.toString()});
		c.close();		
	}
	public boolean hasEpisodes(){
		if (this.podcast == null || this.podcast.length()==0 ) {
		return false;
	} else {
		return true;
	}
	}
		
	public void setProgramId(Integer programId) {
		this.programId = programId;
	}

	public Program(Cursor c) {
		super();		
		this.programId = c.getInt(c.getColumnIndex("PROGRAM_ID"));
		this.title = c.getString(c.getColumnIndex("PROGRAM_TITLE"));
		this.category =c.getString(c.getColumnIndex("PROGRAM_CATEGORY"));
		this.description =c.getString(c.getColumnIndex("PROGRAM_DESCRIPTION"));
		this.imageUrl =c.getString(c.getColumnIndex("PROGRAM_IMAGE_URL"));
		this.website =c.getString(c.getColumnIndex("PROGRAM_WEBSITE"));
		this.podcast = c.getString(c.getColumnIndex("PROGRAM_PODCAST"));
	}
}
